//
//  GROrderDetailGoodCell.m
//  YC_GRice
//
//  Created by luojinrong11 on 2018/7/24.
//  Copyright © 2018年 YeCai. All rights reserved.
//

#import "GROrderDetailGoodCell.h"

@interface GROrderDetailGoodCell()
@property (weak, nonatomic) IBOutlet UIImageView *goodImageView;
@property (weak, nonatomic) IBOutlet UILabel *goodNameLabel;

@property (weak, nonatomic) IBOutlet UILabel *specLabel;

@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UILabel *originalLabel;

@property (weak, nonatomic) IBOutlet UILabel *countLabel;

@property (weak, nonatomic) IBOutlet UIButton *returnBt;

@end

@implementation GROrderDetailGoodCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

-(void)setGoodModel:(GROrderListGoodModel *)goodModel{
    _goodModel = goodModel;

    [self.goodImageView sd_setImageWithURL:[NSURL URLWithString:goodModel.imgUrl] placeholderImage:[UIImage imageNamed:@"placeholderImage"]];
    self.goodNameLabel.text = goodModel.goodsName;
    self.specLabel.text = goodModel.specDesc;
    
    self.priceLabel.text = [NSString stringWithFormat:@"￥%.2lf",goodModel.goodsPrice];
    self.originalLabel.text = [NSString stringWithFormat:@"￥%.2lf",goodModel.originPrice];
    self.countLabel.text = [NSString stringWithFormat:@"x%ld", goodModel.quantity];
    self.returnBt.hidden = !goodModel.btnStatus;
    NSString * btTitle;
    switch (goodModel.btnStatus) {
        case 0:
            btTitle = @"";
            break;
        case 1:
             btTitle = @"退货中";
            break;
        case 2:
            btTitle = [NSString stringWithFormat:@"%ld件已退货",  goodModel.returnQuantity];
            break;
        case 3:
            btTitle = @"已退货";
            break;
        case 4:
            btTitle = @"已取消";
            break;
        case 5:
            btTitle = @"申请退货";
            break;
        default:
            btTitle = @"";
            break;
    }
    [self.returnBt setTitle:btTitle forState:UIControlStateNormal];
}

- (IBAction)returnGood:(id)sender {
    if(_goodModel.btnStatus == 5){
        if (_delegate && [_delegate respondsToSelector:@selector(applyReturnGood:DetailCell:)]) {
            [_delegate applyReturnGood:_goodModel DetailCell:self];
        }
    }else{
        if (_delegate && [_delegate respondsToSelector:@selector(skipToReturnProgress:IsReturnGood:)]) {
            [_delegate skipToReturnProgress:_goodModel.orderInfoId IsReturnGood:YES];
        }
        
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
